package gwtappcontainer.shared;

import java.io.Serializable;
import java.util.HashMap;

@SuppressWarnings("serial")
public class ViewProp implements Serializable {
	public String app = "";
	public String view = "";
	public HashMap<String, String> params = new HashMap<String, String>();
	
	public ViewProp() {}
	
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("app = " + app + ", ");
		sb.append("view = " + view + ", ");
		sb.append("params = ");
		
		for (String key : params.keySet()) {
			String value = params.get(key);
			sb.append("{" + key + ", " + value + "}, ");
		}
		
		return sb.toString();
	}
	
	public String getParamsAsString() {
		StringBuilder sb = new StringBuilder();
						
		for (String key : params.keySet()) {
			String value = params.get(key);
			sb.append(key + "=" + value + "&");
		}
		
		String s = sb.toString();
		
		//remove trailing & if it exists				
		if (s.length() > 0 && (s.charAt(s.length()-1) == '&')) {
			s = s.substring(0,  s.length()-1);
		}
				
		return s;
	}
}
